package com.dries.portal.module.portal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/8/6 14:21
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum  ActivityEnum {

    ACTIVITY_OFFLINE(0, "活动下线"),
    ACTIVITY_ONLINE(1, "活动在线"),
    ACTIVITY_COUPON(2, "优惠");


    @EnumValue
    private Integer code;
    private String description;

    @JsonValue
    public String getDescription() {
        return description;
    }

    /**
     * 根据 code 获取 枚举
     * @param code
     * @return
     */
    public static ActivityEnum of(Integer code) {
        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(e -> e.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + "not exists"));
    }


}
